package com.itehima.Function;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Demo04 {
    //引用构造方法
    public static void main(String[] args) {

        //将指定的字符串形式转换为学生对象，数据分为独立的年龄和姓名
        //1.创建集合对象
        ArrayList<String> list = new ArrayList<>();
        //2.添加数据
        Collections.addAll(list, "张无忌,15", "周芷若,14", "赵敏,13", "张强,20", "张三丰,100", "张翠山,40", "张良,35", "王二麻子,37", "谢广坤,41");


//        //实现类型转换的详细分析
//        list.stream().map(new Function<String, Student>() {
//            @Override
//            public Student apply(String s) {
//                String name = s.split(",")[0];
//                int age = Integer.parseInt(s.split(",")[1]);
//                return new Student(name,age);
//            }
//        }).forEach(s-> System.out.println(s));

        //方法引用
        List<Student> newlist = list.stream().map(Student::new).collect(Collectors.toList());
        System.out.println(newlist);
    }
}
